package cn.com.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created with IntelliJ IDEA.
 * User: yue
 * Date: 2018-03-30
 * Time: 21:26
 * Description:
 */
public class HttpUtil {

    public static String doGet(URL url){
        try {
            HttpURLConnection con=(HttpURLConnection) url.openConnection();
            con.setRequestMethod("GET");
            con.setUseCaches(false);
            con.setDoInput(true);
            con.setDoOutput(true);
            con.connect();
            InputStream inputStream=con.getInputStream();
            InputStreamReader streamReader=new InputStreamReader(inputStream);
            BufferedReader reader=new BufferedReader(streamReader);
            StringBuilder builder=new StringBuilder();
            while (reader.ready()){
                builder.append(reader.readLine());
            }
            String response=new String(builder);
            return response;
        }catch (IOException e){
            e.printStackTrace();
        }
        return null;
    }
}
